package com.liang.sendpsy.scheduled;

import com.liang.sendpsy.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@EnableScheduling
@Component
public class SendMailScheduled {
    @Autowired
    private MailService mailService;
    @Value("${spring.mail.username}")
    private String username;
    @Value("${touser}")
    private String toUser;

    @Scheduled(cron = "0 0 17 * * ?")
    public void sendMail() {
        try {
            mailService.sendMail(username, toUser);
            log.info("已发送==================>");
        } catch (Exception e) {
            log.error("定时任务：发送邮件失败,{}", e);
        }
    }
}
